// 统计出现次数最多的字符


function findMostFrequentChars(str) {
  // 统计字符出现次数
  const charCount = new Map();
  for (const char of str) {
    charCount.set(char, (charCount.get(char) || 0) + 1);
  }

  // 找出最大出现次数
  let maxCount = 0;
  charCount.forEach(count => {
    if (count > maxCount) {
      maxCount = count;
    }
  });

  // 筛选出所有出现次数等于最大值的字符
  const mostFrequentChars = [];
  charCount.forEach((count, char) => {
    if (count === maxCount) {
      mostFrequentChars.push(char);
    }
  });

  return mostFrequentChars;
}

// 示例测试
console.log(findMostFrequentChars("abracadabra")); // 输出 ['a', 'r']
console.log(findMostFrequentChars("hello world")); // 输出 ['l']
